<template>
    <Modal :value="modalShow" title="公告编辑" @on-ok="okSubmit"  @on-cancel="cancel">
        <p>
        <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
            <FormItem label="标题" prop=" title">
                <Input v-model="formValidate.title" placeholder="输入公告标题"></Input>
            </FormItem>
           
        </Form>
        </p>
    </Modal>
</template>
<script>
    export default {

        name: 'UserEdit',

        props: {
            modalShow: {
                type: Boolean,
                default:false
            }
        },
        data () {
            return {
                formValidate: {
                    username: '',
                    phone: '',
                    state: '0',
                },
                ruleValidate: {
                    username: [
                        { required: true, message: 'The name cannot be empty', trigger: 'blur' }
                    ],
                    phone: [
                        { required: true, message: 'The name cannot be phone', trigger: 'blur' },
                    ],
                    state: [
                        { required: true, message: 'Please select the state', trigger: 'change' }
                    ],
                },
            }
        },
        methods: {
            okSubmit() {
                //表单提交
                var _this = this
                this.$refs['formValidate'].validate(valid => {
                    if(!valid) {
                        this.$Message.error('done')
                        this.$emit('on-close', 'close');
                        return false
                    }
                    let postData = JSON.parse(JSON.stringify(this.$data.formValidate))
                    this.$axios.post(process.env.API_HOST+'user/state',postData).then ((res)=> {
                      if(res.data.code===0){
                          setTimeout(() => {
                              _this.$emit('on-close', 'close');
                              _this.$Message.success(res.data.msg);
                          }, 500);
                      }else{
                          _this.$Message.error(res.data.msg);
                      }
                    }).catch(function (error) {
                        _this.$emit('on-close', 'close');
                        _this.$Message.error(error);
                    });
                });
            },
            cancel() {
                this.$emit('on-close', 'close');
            },
        }
    }
</script>